font chooser: Make repeated Escape cancel the dialog
authorMatthias Clasen <mclasen@redhat.com>
Mon, 10 Aug 2015 18:32:22 +0000 (20:32 +0200)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 11 Aug 2015 02:43:19 +0000 (22:43 -0400)
The first Escape clears the search entry, the second Escape
closes the dialog.

gtk/gtkfontchooserwidget.c

index 6f1701f80c0941fe25230a84d3480075d51397b3..956119f3415967150f64b89bba65ed0c38a874a3 100644 (file)
@@ -47,6 +47,7 @@
 #include "gtktreeview.h"
 #include "gtkwidget.h"
 #include "gtksettings.h"
+#include "gtkdialog.h"
 
 /**
  * SECTION:gtkfontchooserwidget
@@ -310,7 +311,20 @@ static void
 stop_search_cb (GtkEntry             *entry,
                 GtkFontChooserWidget *fc)
 {
-  gtk_entry_set_text (entry, "");
+  if (gtk_entry_get_text (entry)[0] != 0)
+    gtk_entry_set_text (entry, "");
+  else
+    {
+      GtkWidget *dialog;
+      GtkWidget *button = NULL;
+
+      dialog = gtk_widget_get_ancestor (GTK_WIDGET (fc), GTK_TYPE_DIALOG);
+      if (dialog)
+        button = gtk_dialog_get_widget_for_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL);
+
+      if (button)
+        gtk_widget_activate (button);
+    }
 }
 
 static void